package com.dg.lecheng.manager.controller;

import com.dg.lecheng.api.user.service.InfoRoleAuthService;
import com.dg.lecheng.base.core.model.BaseResult;
import com.dg.lecheng.base.core.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2017/10/22 0022.
 */
@Api(value = "InfoRoleAuthController" ,description = "角色资源Controller")
@Controller
@RequestMapping("/infoRoleAuth")
public class InfoRoleAuthController extends BaseController {

    @Autowired
    private InfoRoleAuthService infoRoleAuthService;

    @ApiOperation("获取角色和资源")
    @RequestMapping(value = "/findRoleAndAuth" ,method = RequestMethod.GET)
    @ResponseBody
    public Object findRoleAndAuth(@ApiParam(name = "roleId" ,value = "角色ID")@RequestParam(value = "roleId",required = false) int roleId,
                                    @ApiParam(name = "userId" ,value = "用户Id")@RequestParam(value = "userId",required = false) int userId){
        return BaseResult.success(infoRoleAuthService.findRoleAndAuth(userId,roleId));
    }

    /**
     * 为角色授权资源
     * @param roleId
     * @param authIds
     * @return
     */
    @RequestMapping(value = "/addAuthForRole" ,method = RequestMethod.POST)
    @ResponseBody
    public Object addAuthForRole(@RequestParam("roleId")Integer roleId, @RequestParam("authIds") List<Integer> authIds){
        if(roleId == null){
            return BaseResult.fail("1");
        }
        infoRoleAuthService.addRoleAndAuthList(roleId,authIds);
        return BaseResult.success("1");
    }

}
